<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Zhou Wenying
  Date: 2023/3/15
  Time: 23:09
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<link rel="stylesheet" href="/static/css/Cart.css">
<html>
<head>
    <title>购物车</title>
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="pragma" content="no-cache">
</head>
<body>
<jsp:include page="/page/head2.jsp"></jsp:include>

<!--cart-items-->
<div class="cart-items">
    <div class="container">

<%--        <h2>我的购物车</h2>--%>
        <h3 class="Contitle">购物车信息</h3>

        <input  type="checkbox" style="vertical-align: middle; width: 15px; height: 15px;" id="boxid" onclick="selectAllOrNo();">全选/全不选 &nbsp&nbsp&nbsp
        <input style="background-color: #f7e1b5;" class="btn btn-danger" type="button" value="反选" onclick="selectOthers();"/>&nbsp&nbsp&nbsp
        <input class="btn btn-danger" type="button" value="删除" onclick="deleteAll();"/>
        </br></br></br>

        <c:forEach items="${books}" var="book">
            <div class="cart-header col-md-6">
                <div class="cart-sec simpleCart_shelfItem">
                    <div class="cart-item cyc">
                        <a href="#">
                            <input style="width: 15px; height: 15px;" type="checkbox" name="a" value="${book.bookId}">
                            <img src="/getImg?img=${book.bookImg}" class="img-responsive">
                        </a>
                    </div>
                    <div class="cart-item-info">
                        <h3><a href="#">${book.bookName}</a></h3><br/>
                        <div class="prices">
                            <span class="pricesClass" style="color: black;font-size: 25px">￥${book.bookMoney}</span>
                            &nbsp;&nbsp;&nbsp
                            <span style="color: #666;font-size: 25px"><del>￥${book.bookOldMoney}</del></span>
                        </div><br/><br/>
                        <a class="btn btn-danger" href="javascript:delCart(${book.bookId});">删除</a>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </c:forEach>

        <div class="cart-header col-md-12">
            <hr>
            <h4 id="total">订单总金额: ¥ ${total}</h4>
            <button id="btSubmit" class="btn btn-success btn-lg" style="margin-left:74%">提交订单</button>
        </div>



    </div>
</div>
<!--//cart-items-->


<jsp:include page="footer.jsp"></jsp:include>
</body>
</html>

<script>

    $(function () {
        <c:forEach items="${noBookId}" var="id">
            bookListDelete(${id});
            layer.msg("有失效书籍！");
        </c:forEach>
    });

    //全选
    function selectAll(){
        var tag = document.getElementsByName("a");
        for(var i = 0;i < tag.length;i++){
            var ai = tag[i];
            ai.checked = true;
        }
    }

    //全不选
    function selectNo(){
        var tag = document.getElementsByName("a");
        for(var i = 0;i < tag.length;i++){
            var ai = tag[i];
            ai.checked = false;
        }
    }

    //反选
    function selectOthers(){
        var tag = document.getElementsByName("a");
        for(var i = 0;i < tag.length;i++){
            var ai = tag[i];
            if(ai.checked == true){
                ai.checked = false;
            }else{
                ai.checked = true
            }

        }
    }

    //全选/全不选
    function selectAllOrNo(){
        var sel = document.getElementById("boxid");
        if(sel.checked == false){
            selectNo();
        }else{
            selectAll();
        }
    }

    //删除
    function deleteAll(){
        var tag = document.getElementsByName("a");
        for(var i = 0;i < tag.length;i++){
            var ai = tag[i];
            if (ai.checked){
                console.log("valueof"+ai.value);
                bookListDelete(ai.value);
            }
        }
        layer.msg('删除成功',{
            icon:1,
            time:2000
        });
        toBookCartClick();
    }

    $("#btSubmit").click(function () {
        var href="/Cart-indent?"//bookId={book.bookId}

        var tag = document.getElementsByName("a");
        for(var i = 0;i < tag.length;i++){
            var ai = tag[i];
            if(ai.checked == true){
                href+="bookIds="+ai.value+"&";
            }
        }
        window.location.href = href;
    });

</script>

